home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_04 / suereth / timeexp.c < prev   
C/C++ Source or Header  |  1994-02-13  |  34KB  |  931 lines

  1. Listing 1       The expansion code for time
  2.  
  3.  
  4. /* Copyright (c) 1993 Russell Suereth                */
  5.  
  6. #include "natural.h"
  7. #define  PROBABILITY                  220
  8. #define  CHARACTERISTIC               221
  9. #define  LOGICAL_NECESSITY            222
  10. #define  TENSES_ERROR                 210
  11. #define  TIME_MEANING_ERROR           211
  12. #define  NUMBER_ERROR                 212
  13. #define  POINT_OF_TIME                100
  14. #define  DAY                          101
  15. #define  PERIOD_OF_TIME               102
  16. #define  DURATION                     103
  17. #define  BEFORE                       104
  18. #define  AFTER                        105
  19. #define  SINCE                        106
  20. #define  BETWEEN                      107
  21. #define  UNTIL                        108
  22. #define  LAST                         111
  23. #define  NEXT                         112
  24. #define  EACH                         113
  25. #define  EVERY                        114
  26. #define  ALL                          115
  27. int  ask_meaning(void);
  28. void check_time(void);
  29. void derive_aux_meaning(void);
  30. void derive_time_meaning(void);
  31. int  check_agreement(void);
  32. void check_time(void);
  33. void agreement_error(int);
  34. void aux_meaning_response(void);
  35. int  check_underlying3(void);
  36. char times[20][31];
  37. unsigned char time_meaning[20];
  38.  
  39. /*****************************************************/
  40. /* Determine if the input sentence contains a known, */
  41. /* underlying structure. If it does, then assign the */
  42. /* correct types and phrases for the words.          */
  43. /*****************************************************/
  44. int  check_underlying()
  45. {
  46.     int i = 0;
  47.     /* Structure PRON-AUX-VERB-PREP-DET-NOUN         */
  48.     if ( (check_type("PRON",   i) == 0) &&
  49.          (check_type("AUX",  i+1) == 0) &&
  50.          (check_type("VERB", i+2) == 0) &&
  51.          (check_type("PREP", i+3) == 0) &&
  52.          (check_type("DET",  i+4) == 0) &&
  53.          (check_type("NOUN", i+5) == 0) ) {
  54.         strcpy(prime_types[i],   "PRON");
  55.         strcpy(prime_types[i+1], "AUX");
  56.         strcpy(prime_types[i+2], "VERB");
  57.         strcpy(prime_types[i+3], "PREP");
  58.         strcpy(prime_types[i+4], "DET");
  59.         strcpy(prime_types[i+5], "NOUN");
  60.         strcpy(phrases[i],   "NOUNPHRASE");
  61.         strcpy(phrases[i+1], "VERBPHRASE");
  62.         strcpy(phrases[i+2], "VERBPHRASE");
  63.         strcpy(phrases[i+3], "PREPPHRASE");
  64.         strcpy(phrases[i+4], "PREPPHRASE");
  65.         strcpy(phrases[i+5], "PREPPHRASE");
  66.         strcpy(auxiliaries[sentence], word_array[i+1]);
  67.         get_aux();
  68.         return(0);
  69.     }
  70.  
  71.     /* Structure NAME-AUX-VERB-PREP-DET-NOUN         */
  72.     if ( (check_type("NAME",   i) == 0) &&
  73.          (check_type("AUX",  i+1) == 0) &&
  74.          (check_type("VERB", i+2) == 0) &&
  75.          (check_type("PREP", i+3) == 0) &&
  76.          (check_type("DET",  i+4) == 0) &&
  77.          (check_type("NOUN", i+5) == 0) ) {
  78.         strcpy(prime_types[i],   "NAME");
  79.         strcpy(prime_types[i+1], "AUX");
  80.         strcpy(prime_types[i+2], "VERB");
  81.         strcpy(prime_types[i+3], "PREP");
  82.         strcpy(prime_types[i+4], "DET");
  83.         strcpy(prime_types[i+5], "NOUN");
  84.         strcpy(phrases[i],   "NOUNPHRASE");
  85.         strcpy(phrases[i+1], "VERBPHRASE");
  86.         strcpy(phrases[i+2], "VERBPHRASE");
  87.         strcpy(phrases[i+3], "PREPPHRASE");
  88.         strcpy(phrases[i+4], "PREPPHRASE");
  89.         strcpy(phrases[i+5], "PREPPHRASE");
  90.         strcpy(auxiliaries[sentence], word_array[i+1]);
  91.         get_aux();
  92.         return(0);
  93.     }
  94.  
  95.     /* Structure NAME-AUX-AUX-AUX-VERB-PREP-TIME-TIME*/
  96.     if ( (check_type("NAME",   i) == 0) &&
  97.          (check_type("AUX",  i+1) == 0) &&
  98.          (check_type("AUX",  i+2) == 0) &&
  99.          (check_type("AUX",  i+3) == 0) &&
  100.          (check_type("VERB", i+4) == 0) &&
  101.          (check_type("PREP", i+5) == 0) &&
  102.          (check_type("TIME", i+6) == 0) &&
  103.          (check_type("TIME", i+7) == 0) ) {
  104.         strcpy(prime_types[i],   "NAME");
  105.         strcpy(prime_types[i+1], "AUX");
  106.         strcpy(prime_types[i+2], "AUX");
  107.         strcpy(prime_types[i+3], "AUX");
  108.         strcpy(prime_types[i+4], "VERB");
  109.         strcpy(prime_types[i+5], "TIME");
  110.         strcpy(prime_types[i+6], "TIME");
  111.         strcpy(prime_types[i+7], "TIME");
  112.         strcpy(phrases[i],   "NOUNPHRASE");
  113.         strcpy(phrases[i+1], "VERBPHRASE");
  114.         strcpy(phrases[i+2], "VERBPHRASE");
  115.         strcpy(phrases[i+3], "VERBPHRASE");
  116.         strcpy(phrases[i+4], "VERBPHRASE");
  117.         strcpy(phrases[i+5], "TIMEPHRASE");
  118.         strcpy(phrases[i+6], "TIMEPHRASE");
  119.         strcpy(phrases[i+7], "TIMEPHRASE");
  120.         strcpy(auxiliaries[sentence], word_array[i+1]);
  121.         strcat(auxiliaries[sentence], " ");
  122.         strcat(auxiliaries[sentence], word_array[i+2]);
  123.         strcat(auxiliaries[sentence], " ");
  124.         strcat(auxiliaries[sentence], word_array[i+3]);
  125.         get_aux();
  126.         return(0);
  127.     }
  128.  
  129.     /* Structure NAME-AUX-AUX-AUX-VERB-PREP-TIME     */
  130.     if ( (check_type("NAME",   i) == 0) &&
  131.          (check_type("AUX",  i+1) == 0) &&
  132.          (check_type("AUX",  i+2) == 0) &&
  133.          (check_type("AUX",  i+3) == 0) &&
  134.          (check_type("VERB", i+4) == 0) &&
  135.          (check_type("PREP", i+5) == 0) &&
  136.          (check_type("TIME", i+6) == 0) ) {
  137.         strcpy(prime_types[i],   "NAME");
  138.         strcpy(prime_types[i+1], "AUX");
  139.         strcpy(prime_types[i+2], "AUX");
  140.         strcpy(prime_types[i+3], "AUX");
  141.         strcpy(prime_types[i+4], "VERB");
  142.         strcpy(prime_types[i+5], "TIME");
  143.         strcpy(prime_types[i+6], "TIME");
  144.         strcpy(phrases[i],   "NOUNPHRASE");
  145.         strcpy(phrases[i+1], "VERBPHRASE");
  146.         strcpy(phrases[i+2], "VERBPHRASE");
  147.         strcpy(phrases[i+3], "VERBPHRASE");
  148.         strcpy(phrases[i+4], "VERBPHRASE");
  149.         strcpy(phrases[i+5], "TIMEPHRASE");
  150.         strcpy(phrases[i+6], "TIMEPHRASE");
  151.         strcpy(auxiliaries[sentence], word_array[i+1]);
  152.         strcat(auxiliaries[sentence], " ");
  153.         strcat(auxiliaries[sentence], word_array[i+2]);
  154.         strcat(auxiliaries[sentence], " ");
  155.         strcat(auxiliaries[sentence], word_array[i+3]);
  156.         get_aux();
  157.         return(0);
  158.     }
  159.  
  160.     /* Structure NAME-AUX-AUX-AUX-VERB-TIME-TIME     */
  161.     if ( (check_type("NAME",   i) == 0) &&
  162.          (check_type("AUX",  i+1) == 0) &&
  163.          (check_type("AUX",  i+2) == 0) &&
  164.          (check_type("AUX",  i+3) == 0) &&
  165.          (check_type("VERB", i+4) == 0) &&
  166.          (check_type("TIME", i+5) == 0) &&
  167.          (check_type("TIME", i+6) == 0) ) {
  168.         strcpy(prime_types[i],   "NAME");
  169.         strcpy(prime_types[i+1], "AUX");
  170.         strcpy(prime_types[i+2], "AUX");
  171.         strcpy(prime_types[i+3], "AUX");
  172.         strcpy(prime_types[i+4], "VERB");
  173.         strcpy(prime_types[i+5], "TIME");
  174.         strcpy(prime_types[i+6], "TIME");
  175.         strcpy(phrases[i],   "NOUNPHRASE");
  176.         strcpy(phrases[i+1], "VERBPHRASE");
  177.         strcpy(phrases[i+2], "VERBPHRASE");
  178.         strcpy(phrases[i+3], "VERBPHRASE");
  179.         strcpy(phrases[i+4], "VERBPHRASE");
  180.         strcpy(phrases[i+5], "TIMEPHRASE");
  181.         strcpy(phrases[i+6], "TIMEPHRASE");
  182.         strcpy(auxiliaries[sentence], word_array[i+1]);
  183.         strcat(auxiliaries[sentence], " ");
  184.         strcat(auxiliaries[sentence], word_array[i+2]);
  185.         strcat(auxiliaries[sentence], " ");
  186.         strcat(auxiliaries[sentence], word_array[i+3]);
  187.         get_aux();
  188.         return(0);
  189.     }
  190.  
  191.     /* Structure NAME-AUX-AUX-VERB-PREP-TIME-TIME    */
  192.     if ( (check_type("NAME",   i) == 0) &&
  193.          (check_type("AUX",  i+1) == 0) &&
  194.          (check_type("AUX",  i+2) == 0) &&
  195.          (check_type("VERB", i+3) == 0) &&
  196.          (check_type("PREP", i+4) == 0) &&
  197.          (check_type("TIME", i+5) == 0) &&
  198.          (check_type("TIME", i+6) == 0) ) {
  199.         strcpy(prime_types[i],   "NAME");
  200.         strcpy(prime_types[i+1], "AUX");
  201.         strcpy(prime_types[i+2], "AUX");
  202.         strcpy(prime_types[i+3], "VERB");
  203.         strcpy(prime_types[i+4], "TIME");
  204.         strcpy(prime_types[i+5], "TIME");
  205.         strcpy(prim